<template>
  <Form :model="form" :rules="rules" @keydown.enter.native="handleSubmit" ref="loginForm">
    <FormItem prop="username">
      <Input placeholder="请输入用户名" style="height:40px!important" v-model="form.username">
        <span slot="prepend">
          <Icon :size="16" type="ios-person"></Icon>
        </span>
      </Input>
    </FormItem>
    <FormItem prop="password">
      <Input
        placeholder="请输入密码"
        style="height:40px!important"
        type="password"
        v-model="form.password"
      >
        <span slot="prepend">
          <Icon :size="14" type="md-lock"></Icon>
        </span>
      </Input>
    </FormItem>
     <div class="errShow" v-if="isShowError!=0">{{isShowError==1?"该账号已冻结":"账号或密码错误!"}}</div>
    <FormItem>

      <Button @click="handleSubmit" long style="height:40px" type="success" class="logbtn">登录</Button>
    </FormItem>
  </Form>
</template>
<script>
export default {
  name: 'LoginForm',
  props: {
    userNameRules: {
      type: Array,
      default: () => {
        return [{ required: true, message: '账号不能为空', trigger: 'blur' }];
      }
    },
    passwordRules: {
      type: Array,
      default: () => {
        return [{ required: true, message: '密码不能为空', trigger: 'blur' }];
      }
    },
    isShowError: {
      type: Number,
      default: 0

    }
  },
  data () {
    return {
      form: {
        username: '',
        password: ''

      }
    };
  },
  computed: {
    rules () {
      return {
        username: this.userNameRules,
        password: this.passwordRules
      };
    }
  },
  methods: {
    handleSubmit () {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.$emit('on-success-valid', {
            username: this.form.username,
            password: this.form.password
          });
        }
      });
    }
  }
};
</script>

<style lang="less" scoped>
/deep/ .ivu-input {
  height: 40px;
}
.logbtn{
  background-color:#5A6FCE;
  border-color: #ffffff
}
 .logbtn:hover{
  background-color:#455BC3;
  border-color: #ffffff
}
.errShow{
text-align: left;
    margin-bottom: 10px;
    color: red;
}
</style>
